package com.foodmarket.mapper;

import com.foodmarket.pojo.FoodItems;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface FoodMapper {
    //新增食品数据
    @Insert("insert into fooditems(food_name,food_price,expiry_date,food_image_url,seller_id,stock_quantity,food_description)" +
            "values(#{foodName},#{foodPrice},#{expiryDate},#{foodImageUrl},#{sellerId},#{stockQuantity},#{foodDescription})")
    void addFood(FoodItems foodItems);

    @Select("select * from fooditems where food_name=#{foodName}")
    FoodItems findByFoodName(String foodName);

    @Select("select* from fooditems where seller_id=#{sellerId}")
    List<FoodItems> findAllFood(int sellerId);

    @Update("update fooditems set stock_quantity=#{foodItems.stockQuantity},food_price=#{foodItems.foodPrice}")
    void updateFood(@Param("foodItems") FoodItems foodItems);

    @Delete("DELETE FROM fooditems WHERE food_name=#{foodName}")
    void deleteFood(String foodName);


    @Select("select * from fooditems")
    List<FoodItems> findAllFoodItems(int buyerId);

    @Select("SELECT food_name,food_price,expiry_date,food_image_url,stock_quantity,food_description,store_name " +
            "FROM  FoodItems " +
            "JOIN  " +
            " Sellers  ON FoodItems.seller_id = Sellers.seller_id WHERE food_id = #{foodId}")
    FoodItems findByFoodId(Integer foodId);
}
